<template>
	<view class="content">
		<view class="navBar">
			<view class="left">
				<navigator url="../all-activities/all-activities" open-type="switchTab">
					<uni-icons class="right-icon" type="arrowleft" size="20" color="#fff"></uni-icons>
				</navigator>
				
			</view>
			<view class="center">
				<text class="uni-tab-item-title">{{kindName}}</text>
			</view>
			<view class="right">
				<uni-icons class="right-icon" type="redo" size="20" color="#fff"></uni-icons>
				
			</view>
		</view>
		<view style="width: 100%;height: 90rpx;"></view>
		<view class="background">
			<image :src="comp.compPoster"></image>
		</view>
		<view class="competition-info">
			<view class="competition-title"><text>{{comp.compName}}</text></view>
			<view class="competition-time">
				<text style="float: left;margin-left: 40rpx;">主办方：{{comp.compHolder}}</text>
				<text>{{renderTime(comp.startTime)}}-{{renderTime(comp.endTime)}}</text>
			</view>
			<view class="competition-rules"><text>{{comp.compIntro}}</text></view>
		</view>
		<view class="choose-new-hot" >
			<text v-for="(item,index) in chooseItems" @click="onClickItem" :id="index"  class="new-hot" :class="chooseIndex == index ? 'new-hot-active' : ''">{{item}}</text>
		</view>
		<view class="new" v-if="chooseIndex == 0">
				<view class="work-card" v-for="(item,index) in newArt">
					<view class="info">
						<view class="info-photo"><image :src="item.user.avatar"></image></view>
						<view class="info-text">
							<view><text class="info-name">{{item.user.userName}}</text></view>
							<view><text class="info-time">{{renderTime(item.workPostTime)}}</text></view>
						</view>
					</view>
					<view class="work-content">
						<view class="describe">{{item.workIntro}}</view>
						<view class="pic"><image :src="item.workImg"></image></view>
						<view class="vote">
							<uni-icons class="num" type="hand-thumbsup" size="20" color="#333333"></uni-icons>
							<text style="color: #333333;">{{item.workVoteNum}}</text>
						</view>
						
					</view>
					
				</view>
			
		</view>
		<view class="hot" v-if="chooseIndex == 1">
			<view class="work-card" v-for="(item,index) in hotArt">
				<view class="info">
					<view class="info-photo"><image :src="item.user.avatar"></image></view>
					<view class="info-text">
						<view><text class="info-name">{{item.user.userName}}</text></view>
						<view><text class="info-time">{{renderTime(item.workPostTime)}}</text></view>
					</view>
				</view>
				<view class="work-content">
					<view class="describe">{{item.workIntro}}</view>
					<view class="pic"><image :src="item.workImg"></image></view>
					<view class="vote">
						<uni-icons class="num" type="hand-thumbsup" size="20" color="#333333"></uni-icons>
						<text style="color: #333333;">{{item.workVoteNum}}</text>
					</view>
					
				</view>
				
			</view>
				</view>
		<view style="width: 100%;height: 100rpx;"></view>
		<view>
			<navigator url="work-submit"><button class="enter-button">立即参与</button></navigator>
		</view>
		
	</view>
</template>

<script>
	export default{
		onLoad(){
			this.getComDetail('aiqiu',4);
			this.getNewArt(4,1,10,1);
			this.getHotArt(4,1,10,0);
		},
		data(){
			return{
				comp: {},
				newArt:[],
				hotArt:[],
				user: 'aiqiu',
				kindName:'鲸意杯油画比赛',
				backImage:'../../../static/online-competition/competition-poster.png',
				title:'2020鲸意杯油画大赛正式开启',
				time:'2020年12月15日0:00至2020年12月30日',
				rules:'通过活动底下的按钮上传照片（并且配上简介，需原创）。12月30日24:00累计得票第一名可以获得iPhone 12 Pro Max一台，第二名可以获得小米10手机一台，第三名可以获得高品质油画工具一套。（每人仅限一张作品)',
				chooseItems:['最新','最热'],
				chooseIndex:0,
				works:[
					{
						id:1,
						infoImageurl:"../../../static/swiper/1.jpg",
						infoname:"灵感事务所",
						infotime:"2020.09.30",
						describe:"这幅油画是我画的向日葵，模仿了梵高的画风，创作不易，希望大家多多投票支持",
						pic:"../../../static/swiper/1.jpg",
						num:330
					},
					{
						id:2,
						infoImageurl:"../../../static/swiper/2.jpg",
						infoname:"灵感事务所",
						infotime:"2020.09.30",
						describe:"这幅油画是我画的向日葵，模仿了梵高的画风，创作不易，希望大家多多投票支持",
						pic:"../../../static/swiper/2.jpg",
						num:201
					},
					{
						id:3,
						infoImageurl:"../../../static/swiper/3.jpg",
						infoname:"灵感事务所",
						infotime:"2020.09.30",
						describe:"这幅油画是我画的向日葵，模仿了梵高的画风，创作不易，希望大家多多投票支持",
						pic:"../../../static/swiper/3.jpg",
						num:134
					},
					{
						id:4,
						infoImageurl:"../../../static/swiper/4.jpg",
						infoname:"灵感事务所",
						infotime:"2020.09.30",
						describe:"这幅油画是我画的向日葵，模仿了梵高的画风，创作不易，希望大家多多投票支持",
						pic:"../../../static/swiper/4.jpg",
						num:98
					}
				]
			}
		},
		methods:{
			onClickItem(e) {
				this.chooseIndex = e.currentTarget.id
			},
			//修改时间格式：年月日
			renderTime(date) {
			  var dateee = new Date(date).toJSON();
			  return new Date(+new Date(dateee) + 8 * 3600 * 1000)
						.toISOString()
						.replace(/T/g, ' ')
						.replace(/\.[\d]{3}Z/, '') 
						.replace(/-/g, ".")
						.substring(0, 10)
			},
			getComDetail(userId,compId){
				uni.request({
					url: "http://ronin.fun:8888/comp/detail",
					data:{
						compId:compId,
						userId:userId
					},
					success: (res) => {
						this.comp = res.data.data;
						console.log(this.comp);
					}
				})
			},
			getNewArt(compId,current,size,type){
				uni.request({
					url:"http://ronin.fun:8888/comp/work/list",
					data:{
						compId:compId,
						current:current,
						size:size,
						type:type
					},
					success: (res) => {
						this.newArt = res.data.data.records;
						console.log(this.newArt);
					}
				})
			},
			getHotArt(compId,current,size,type){
				uni.request({
					url:"http://ronin.fun:8888/comp/work/list",
					data:{
						compId:compId,
						current:current,
						size:size,
						type:type
					},
					success: (res) => {
						this.hotArt = res.data.data.records;
						console.log(this.hotArt);
					}
				})
			}
		}
	}
</script>

<style lang="scss"> 
	.content {
		width: 100%;
		height: 100%;
		// 导航栏
		.navBar{
			z-index: 1000;
			position: fixed;
			width: 100%;
			height: 90rpx;
			display: flex;
			background-color: #B0E3FF;
			.left{
				display: inline-block;
				height: 100%;
				width: 200rpx;
				.right-icon{
					margin-left: 20rpx;
					line-height: 90rpx;
				}
			}
			.center{
				display: inline-block;
				height: 100%;
				flex: 1;
				text-align: center;
				line-height: 90rpx;
				.uni-tab-item {
					/* #ifndef APP-PLUS */
					display: inline-block;
					/* #endif */
					flex-wrap: nowrap;
					padding-left: 10rpx;
					padding-right: 10rpx;
				}
				.uni-tab-item-title {
					color: #FFFFFF;
					font-size: 30rpx;
					font-weight: bold;
					height: 80rpx;
					line-height: 80rpx;
					flex-wrap: nowrap;
					/* #ifndef APP-PLUS */
					white-space: nowrap;
					/* #endif */
				
				}
				.uni-tab-item-title-active {
					color: #FFFFFF;
					font-weight: bold;
					font-size: 40rpx;
					// border-bottom: solid #797979;
				}
			}
			.right{
				display: inline-block;
				height: 100%;
				width: 200rpx;
				text-align: center;
				align-items: center;
				.right-icon{
					margin-left: 20rpx;
					line-height: 90rpx;
				}
			}
			
		}
		.background{
			width: 100%;
			height: 800rpx;
			image{
				width: 100%;
				height: 100%;
			}
		}
		.competition-info{
			.competition-title{
				font-size: 40rpx;
				font-weight: bold;
				color: #333333;
				text-align: center;
				margin-top: 20rpx;
			}
			.competition-time{
				font-size: 30rpx;
				color: #555555;
				text-align: center;
				margin-top: 20rpx;
			}
			.competition-rules{
				font-size: 30rpx;
				color: #333333;
				padding-left: 20rpx;
				padding-right: 20rpx;
				margin-top: 20rpx;
			}
		}
		.choose-new-hot{
			width: 100%;
			height: 100rpx;
			margin-top: 20rpx;
			.new-hot{
				margin-left: 30rpx;
				color: #555555;
				font-size: 40rpx;
				
			}
			.new-hot-active{
				margin-left: 30rpx;
				color: #B0E3FF;
				font-size: 50rpx;
				font-weight: bold;
			}
		}
		.work-card{
			// width: 100%;
			padding: 20rpx 30rpx 20rpx 30rpx;
			height: 740rpx;
			box-shadow: 0px 2px 1px rgba(200,200,200,.30);
			.info{
				width: 100%;
				height: 120rpx;
				display: flex;
				.info-photo{
					width: 120rpx;
					height: 120rpx;
					border-radius: 100rpx;
					display: inline-block;
					text-align: center;
					image{
						width: 120rpx;
						height: 120rpx;
						border-radius: 100rpx;
					}
				}
				.info-text{
					display: inline-block;
					flex: 1;
					margin-top: 20rpx;
					.info-name{
						font-size: 30rpx;
						font-weight: bold;
						margin-left: 20rpx;
						color: #333333;
					}
					.info-time{
						font-size: 25rpx;
						color: #555555;
						margin-left: 20rpx;
					}
				}
			}
			.work-content{
				.describe{
					width: 100%;
					// padding-left: 20rpx;
					// padding-right: 20rpx;
					margin-top: 20rpx;
					font-size: 30rpx;
					color: #333333;
					overflow: hidden;
					-webkit-line-clamp: 2;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-box-orient: vertical;
				}
				.pic{
					margin-top: 20rpx;
					text-align: center;
					image{
						height: 400rpx;
					}
				}
				.vote{
					float: right;
					margin-right: 80rpx;
					margin-top: 10rpx;
					.num{
						color: #333333;
						// float: right;
						margin-right: 40rpx;
					}
				}
			}
			.text{
				display: inline-block;
				vertical-align: top;
				margin-top: 20rpx;
				.int-card-text{
					text-align: center;
					color: #797979;
					font-size: 30rpx;
					margin-top: 20rpx;
					line-height: 50rpx;
					margin-bottom: 20rpx;
					.name{
						text-align: center;
						color: #333333;
						font-weight: bold;
						font-size: 40rpx;
						line-height: 60rpx;
						margin-top: 20rpx;
						margin-bottom: 20rpx;
					}
				}
				.int-card-label{
					vertical-align: middle;
					margin-top: 20rpx;
					.label{
						width: 100rpx;
						height: 40rpx;
						display: inline-block;
						border: 1px solid #B0E3FF;
						color: #B0E3FF;
						border-radius: 20rpx;
						text-align: center;
					}
				}
			}
			
		}
		.enter-button{
			width: 100%;
			background-color: #B0E3FF;
			color: #FFFFFF;
			border-radius: 30rpx;
			position: fixed;
			z-index: 999;
			bottom: 0;
			border: none;
		}
	}
</style>
